package Wuli_2021;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

class work{
    int deadLine;
    int reward;
    work(int deadLine,int reward){
        this.deadLine=deadLine;
        this.reward=reward;
    }
}
public class getMaxReward {
    public int get(int [] deadLine,int []reward,int target){
        List<work>works=new ArrayList<>();
        for(int i=0;i<deadLine.length;i++)
            works.add(new work(deadLine[i],reward[i]));
        works.sort((x,y)->x.reward-y.reward);
        int ans=0;
        int []times=new int[target];  //等于0即空闲
        for(work w:works){
            int dead=w.deadLine;
            boolean haveFree=false;
            for(int i=dead;i>=0;i--)
                if(times[i-1]==0){ //当天没人占用
                    times[i]=1;
                    haveFree=true;
                }
            if(haveFree){   //有空闲时间，作业就可以被完成
                ans+=w.reward;
            }
        }
        return ans;
    }
}
